package primetest.dto;

import java.util.Date;
import java.util.UUID;

public class ChargeDto {
	public static final int STATUS_UNPAID = 1;
	public static final int STATUS_PAID = 2;
	public static final int STATUS_CANCELLED = 3;

	public static final int TYPE_TREATMENT = 1;
	public static final int TYPE_REGISTER = 2;

	private String key;
	private PatientDto patientDto;
	private DoctorDto doctorDto;
	private float fee;
	private Date genDate;
	private Date payDate;
	private int status;
	private int type;
	private int seq;
	private String description;
	private TreatmentRecordDto treatmentRecordDto;

	public ChargeDto() {
		this.key = UUID.randomUUID().toString().substring(0, 8);
		this.status = STATUS_UNPAID;
		this.genDate = new Date(System.currentTimeMillis());
	}

	public ChargeDto(TreatmentRecordDto treatmentRecord) {
		this.key = UUID.randomUUID().toString().substring(0, 8);
		this.patientDto = treatmentRecord.getPatientDto();
		this.doctorDto = null;
		this.fee = treatmentRecord.getFee();
		this.genDate = new Date(System.currentTimeMillis());
		this.payDate = new Date(System.currentTimeMillis());;
		this.status = STATUS_UNPAID;
		this.type = TYPE_TREATMENT;
		this.seq = treatmentRecord.getSeq();
		this.description = treatmentRecord.getMedcineIDsAndNums();
		this.setTreatmentRecordDto(treatmentRecord);
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public PatientDto getPatientDto() {
		return patientDto;
	}

	public void setPatientDto(PatientDto patientDto) {
		this.patientDto = patientDto;
	}

	public DoctorDto getDoctorDto() {
		return doctorDto;
	}

	public void setDoctorDto(DoctorDto doctorDto) {
		this.doctorDto = doctorDto;
	}

	public float getFee() {
		return fee;
	}

	public void setFee(float fee) {
		this.fee = fee;
	}

	public Date getGenDate() {
		return genDate;
	}

	public void setGenDate(Date genDate) {
		this.genDate = genDate;
	}

	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}

	public int getStatus() {
		return status;
	}

	public String getStatusName() {
		switch (status) {
		case STATUS_UNPAID:
			return "Unpaid";
		case STATUS_PAID:
			return "Paid";
		case STATUS_CANCELLED:
			return "Canceled";
		}
		return "Cancelled";
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getType() {
		return type;
	}

	public boolean isTreatmentRecordCharge() {
		return type == TYPE_TREATMENT;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public int getPatientSeq() {
		if (patientDto == null) {
			return -1;
		} else {
			return patientDto.getSeq();
		}
	}

	public int getDoctorSeq() {
		if (doctorDto == null) {
			return -1;
		} else {
			return doctorDto.getSeq();
		}
	}

	public String getPatientName() {
		if (patientDto == null) {
			return "";
		} else {
			return patientDto.getName();
		}
	}

	public String getDoctorName() {
		if (doctorDto == null) {
			return "";
		} else {
			return doctorDto.getName();
		}
	}

	public boolean isValid() {
		return true;
	}

	public void pay(DoctorDto doctor) {
		this.payDate = new Date(System.currentTimeMillis());
		this.status = STATUS_PAID;
		this.doctorDto = doctor;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean getCanPay() {
		return status == STATUS_UNPAID;
	}

	public TreatmentRecordDto getTreatmentRecordDto() {
		return treatmentRecordDto;
	}

	public void setTreatmentRecordDto(TreatmentRecordDto treatmentRecordDto) {
		this.treatmentRecordDto = treatmentRecordDto;
	}
}
